#pragma once

#ifndef __MPU6050_H__
#define __MPU6050_H__

#include <basic.h>

#ifdef __cplusplus
extern "C"
{
#endif

    typedef enum
    {
        MPU_2G = 0x00,
        MPU_4G = 0x08,
        MPU_8G = 0x10,
        MPU_16G = 0x18,
    } mpu_accel_fs_t;
    typedef enum
    {
        MPU_250DPS = 0x00,
        MPU_500DPS = 0x08,
        MPU_1000DPS = 0x10,
        MPU_2000DPS = 0x18,
    } mpu_gyro_fs_t;

    typedef struct
    {
        float ax, ay, az; /*unit: g*/
        float gx, gy, gz; /*unit: °/s*/
    } mpu_acce_gyro_data_t;

    typedef struct
    {
        float pitch, roll, yaw; /*unit: °*/
    } mpu_euler_angle_t;

    void mpu6050_start(mpu_accel_fs_t _accel_fs, mpu_gyro_fs_t _gyro_fs);

    int mpu6050_get_acce_gyro_data(mpu_acce_gyro_data_t *data);
    int mpu6050_get_euler_angle(mpu_euler_angle_t *angle);

    /*
        经过测定，调用本api 在iic_freq=400k Hz，无任何中断触发的条件下 平均需要 620us
        其中，读取数据和计算欧拉角分别需要 420us 和 200us 实际上计算时间大于200us

        要想获得欧拉角 必须周期调用此api 并传入dt
    */
    int mpu6050_loop(mpu_acce_gyro_data_t *acce_gyro_data, mpu_euler_angle_t *angle, float dt);

    void mpu_test_software();

#ifdef __cplusplus
}
#endif

#endif
